home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / comm / mail / YamNet.lha / rexxtra12.lha / Test.rexx < prev   
OS/2 REXX Batch file  |  1990-03-17  |  4KB  |  118 lines

  1. /* test rexxextra.library */
  2.  
  3.  
  4. /*
  5. trace all
  6. */
  7. interpret getclip('Tracing')
  8.  
  9. call pragma('P',-1)
  10. call addlib 'rexxextra.library',-20,-30,0
  11. testa. = ''
  12. testa.0 = d2c(7)||'Not OK';testa.1 = 'OK'
  13. arg xx f .
  14. if xx = '' then xx = 1
  15. if f = '' then f = 'FRCS'
  16. do ii = 1 to xx
  17.   if index(f,'F') > 0 then call testfparse
  18.   if index(f,'R') > 0 then call testreplace
  19.   if index(f,'C') > 0 then call testcparse
  20.   if index(f,'S') > 0 then call testsortwords
  21.   end
  22.  
  23. exit 0
  24.  
  25. testfparse:
  26.   cdir = 'Volume:Dir1/DIR2/d3'
  27.   tt = '.type'
  28.   nn = 'name'
  29.  
  30.   test = fparse(cdir,nn,tt) == cdir'/name.type'
  31.   test = test & fparse(cdir,'//name',tt) ==  'Volume:Dir1/name.type'
  32.   test = test & fparse(cdir,'/dir3/name',tt) ==  'Volume:Dir1/DIR2/dir3/name.type'
  33.   test = test & fparse(cdir,'/name',tt) == 'Volume:Dir1/DIR2/name.type'
  34.   test = test & fparse(cdir,'dir4/name','Source:.type') == cdir'/dir4/name.type'
  35.   test = test & fparse(cdir,'dir4/name','','',',') == 'Volume:,Dir1/DIR2/d3/dir4/,name,'
  36.   test = test & fparse(cdir,nn,tt,'','V') ==  'Volume:'
  37.   test = test & fparse(cdir,nn,tt,'','D') ==  'Dir1/DIR2/d3/'
  38.   test = test & fparse(cdir,'name.type','','','T') ==  tt
  39.   say 'fparse()' testa.test
  40.   return
  41.  
  42. testreplace:
  43.   bb = 'b'
  44.   th = 'this old house is sold'
  45.   test = replace('a',bb,'12b34b5') == '12a34a5'
  46.   test = test & replace('ax',bb,'12b34b5') == '12ax34ax5'
  47.   test = test & replace('','asdf','123asdf456asdfasdf789') == '123456789'
  48.   test = test & replace('abc','ab','abcdeabab') == 'abccdeabcabc'
  49.   test = test & replace('new','old',th) == 'this new house is snew'
  50.   test = test & replace('','old',th) == 'this  house is s'
  51.   say 'replace()' testa.test
  52.   return
  53.  
  54. testcparse: procedure expose testa.
  55.   args. = ''
  56.  
  57.   a1 = 'ARGS.NEW="1";ARGS.REMAIN="file show remainder";ARGS.ERRCODE="1";'
  58.   command = "file new show remainder"
  59.   template = "NEW/S"
  60.   test = cparse(command,template,"ARGS") == a1
  61.  
  62.   a1 = 'ARGS.NEW="1";ARGS.FILE.1="show";ARGS.FILE.2="remainder";' || ,
  63.        'ARGS.FILE.3="none";ARGS.FILE.0="3";ARGS.ERRCODE="0";'
  64.   command = "file new show remainder none"
  65.   template = "NEW/S,FILE/..."
  66.   test = test & cparse(command,template,"ARGS.") == a1
  67.  
  68.   a1 = 'ARGS.NEW="1";ARGS.FILE="filearg";ARGS.REMAIN="show remainder";' || ,
  69.        'ARGS.ERRCODE="1";'
  70.   command = "file filearg new show remainder"
  71.   template = "NEW/S,FILE"
  72.   test = test & a1 == cparse(command,template,"args")
  73.  
  74.   command = 'file "Quoted Arg" new ' || 'help "HELP arg" show remainder'
  75.   template = "NEW/S,FLAG2/S,SHOW/S,HELP/K,FILE"
  76.   a1 = cparse(command,template,"ARGS")
  77.  
  78.   qwer. = ""
  79.   a2 = cparse(command,template,"qwer")
  80.   test = test & a1 == replace("ARGS.","QWER.",a2)
  81.  
  82.   command = 'file "Quoted Arg" flag1 ' || 'help "HELP arg" show remainder'
  83.   a1 = 'Q.FLAG1="1";Q.FLAG2="0";Q.SHOW="1";Q.HELP="HELP arg";' || ,
  84.        'Q.FILE="Quoted Arg";Q.REMAIN="remainder";Q.ERRCODE="1";'
  85.   template = "FLAG1/S,FLAG2/S,SHOW/S,HELP/K,FILE"
  86.   test = test & cparse(command,template,"q") == a1
  87.  
  88.   test = test & ,
  89. Cparse('name volA:dirB/nameC quiet','QUIET/S,NAME/A','args') == ,
  90. 'ARGS.QUIET="1";ARGS.NAME="volA:dirB/nameC";ARGS.ERRCODE="0";'
  91.  
  92.   test = test & ,
  93. Cparse('quiet','QUIET/S,NAME/A','args') == ,
  94. 'ARGS.QUIET="1";ARGS.ERRTEXT="Required argument missing: NAME";ARGS.ERRCODE="2";'
  95.  
  96.   say 'Cparse()' testa.test
  97.  
  98.   return
  99.  
  100. testsortwords:
  101.  
  102.   test = sortwords('refit point zoo asphalt bum') == ,
  103.            'asphalt bum point refit zoo'
  104.   test = test & sortwords('   this   old   house   is   sold   ') == ,
  105.               'house is old sold this'
  106.   test = test & sortwords('every good boy deserves favor') == ,
  107.               'boy deserves every favor good'
  108.   test = test & sortwords('now is the time for all good men') == ,
  109.               'all for good is men now the time'
  110.   test = test & sortwords(' to come to the aid of their country ') == ,
  111.               'aid come country of the their to to'
  112.   test = test & sortwords('asphalt') == 'asphalt'
  113.   test = test & sortwords('') == ''
  114.   say 'sortwords()' testa.test
  115.  
  116.   return
  117.  
  118.